﻿// Type: D2L.Extensibility.AuthSdk.Impl.D2LSigner
// Assembly: D2L.Extensibility.AuthSdk, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
// MVID: B2FBA42B-591C-474F-A782-6FF215FEDFB9
// Assembly location: C:\Users\leandro.perdizo\Desktop\D2L.Extensibility.AuthSdk.dll

using System;
using System.Security.Cryptography;
using System.Text;

namespace D2L.Extensibility.AuthSdk.Impl
{
  internal static class D2LSigner
  {
    internal static string GetBase64HashString(string key, string data)
    {
      return D2LSigner.CustomBase64Encode(D2LSigner.ComputeHash(D2LSigner.GetBytes(key), D2LSigner.GetBytes(data)));
    }

    private static string CustomBase64Encode(byte[] hash)
    {
      return Convert.ToBase64String(hash).Replace("=", "").Replace("+", "-").Replace("/", "_");
    }

    private static byte[] GetBytes(string key)
    {
      return Encoding.UTF8.GetBytes(key);
    }

    private static byte[] ComputeHash(byte[] keyBytes, byte[] dataBytes)
    {
      using (HMACSHA256 hmacshA256 = new HMACSHA256(keyBytes))
        return hmacshA256.ComputeHash(dataBytes);
    }
  }
}
